//File:	oplib.c
#include "oplib.h"
int OpndChk(const char* _argv_,const char* Opnd,int* limparam,int argvNum){
//	Time-Optimize firstly check the length of two parameter
	if(strlen(_argv_)!=strlen(Opnd)){
		return 1;
	}else if(stricmp(_argv_,Oprand[0])==0){
		*limparam=argvNum;
		(*limparam)++;
		return 0;
	}
}
void ResDisp(const char* prefix,const int* result){
	printf("%s  ---\t%d\n",prefix,*result);
	return; 
}
void ErrDisp(const char* ErrorHint){
	system("");			//Avoid cmd/powershell ANSI disorder  
	printf("\033[31m");	//red
	printf("%s:  %s\n","Error",ErrorHint);
	printf("\033[0m");
	return;
}
void WordChk(const char* charFromFile,int* result){
	//0x20 is ' '
	//0x0A is LF 
	//0x0D is return
	if(*charFromFile==0x20/*||PuctChk(charFromFile)*/){
		(*result)++;
	}/*else if(*charFromFile==0x0A||*charFromFile==0x0D){
		(*result)++;
	}else if(*charFromFile==EOF){
		(*result)++;
	}*/ 
	return;
}
int PuctChk(const char* charFromFile){
	//0x2E is '.' 0x21 is '!' 0x3F is '?'
	if((*charFromFile)==0x2E||(*charFromFile)==0x21||(*charFromFile)==0x3F){
		return 1;
	}
	return 0; 
} 
void InitCntNum(int* Char,int* Word,int* Sentence,int* LineCnt){
	(*Char)=-1;
	(*Word)=0;
	(*Sentence)=0;
	(*LineCnt)=0;
	return;
}
void HintDisp(const char* hint){
	system("");			//Avoid cmd/powershell ANSI disorder  
	printf("\033[32m");	//green
	printf("%s:  %s\n"," Hint",hint);
	printf("\033[0m");
	return;
}
void LineChk(const char* charFromFile,int* result){
	if(*charFromFile==0x0A||*charFromFile==0x0D){
		(*result)++;
	}else if(*charFromFile==EOF){
		(*result)++;
	}
	return;
}
int FileTypeChk(const char* _argv_,const char* FileType){
	size_t FileName_Length=strlen(_argv_);
	size_t FileType_Length=strlen(FileType);
	if(strcmp(_argv_+FileName_Length-FileType_Length,FileType)!=0){
		return 1;
	}
	return 0;
}
